load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "explain_gen",
    src = "explain.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "bulk_write_gen",
    src = "bulk_write.idl",
    deps = [
        "//src/mongo/client:read_preference_setting_gen",
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db:write_concern_options_gen",
        "//src/mongo/db/query/write_ops:write_ops_gen",
        "//src/mongo/db/repl:read_concern_args_gen",
        "//src/mongo/db/repl:replication_types_gen",
        "//src/mongo/db/sharding_environment:sharding_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

mongo_cc_library(
    name = "bulk_write_parser",
    srcs = [
        "bulk_write_crud_op.cpp",
        "bulk_write_parser.cpp",
        ":bulk_write_gen",
    ],
    deps = [
        "//src/mongo/crypto:fle_fields",
        "//src/mongo/db:commands",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/query/write_ops:write_ops_parsers",
        "//src/mongo/s:common_s",
    ],
)

idl_generator(
    name = "query_settings_cmds_gen",
    src = "query_settings_cmds.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/auth:access_checks_gen",
        "//src/mongo/db/auth:action_type_gen",
        "//src/mongo/db/query/query_settings:query_settings_gen",
        "//src/mongo/db/query/query_shape:query_shape_hash_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

mongo_cc_library(
    name = "current_op_common",
    srcs = [
        "current_op_common.cpp",
    ],
    deps = [
        "//src/mongo/db:commands",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/commands:test_commands_enabled",
        "//src/mongo/db/pipeline:aggregation_request_helper",
        "//src/mongo/db/query:command_request_response",
    ],
)

idl_generator(
    name = "map_reduce_gen",
    src = "map_reduce.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

idl_generator(
    name = "search_index_commands_gen",
    src = "search_index_commands.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
        "//src/mongo/db/auth:access_checks_gen",
        "//src/mongo/db/auth:action_type_gen",
        "//src/mongo/idl:generic_argument_gen",
    ],
)

mongo_cc_library(
    name = "map_reduce_parser",
    srcs = [
        "map_reduce_out_options.cpp",
        ":map_reduce_gen",
    ],
    deps = [
        "//src/mongo/db:server_base",
    ],
)

mongo_cc_library(
    name = "update_metrics",
    srcs = [
        "update_metrics.cpp",
    ],
    deps = [
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/db/query/write_ops:write_ops_parsers",
    ],
)

mongo_cc_library(
    name = "write_commands_common",
    srcs = [
        "write_commands_common.cpp",
    ],
    deps = [
        ":update_metrics",
        "//src/mongo/db:local_executor",
        "//src/mongo/db/auth",
        "//src/mongo/db/auth:authprivilege",
        "//src/mongo/db/pipeline:lite_parsed_document_source",
        "//src/mongo/db/query/write_ops:write_ops_parsers",
    ],
)

mongo_cc_library(
    name = "bulk_write_common",
    srcs = [
        "bulk_write_common.cpp",
    ],
    deps = [
        ":bulk_write_parser",
        ":update_metrics",
        ":write_commands_common",
        "//src/mongo/db:query_expressions",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/auth:authprivilege",
        "//src/mongo/db/query/write_ops:delete_request_idl",
        "//src/mongo/db/query/write_ops:write_ops_parsers",
        "//src/mongo/logv2:logv2_options",
    ],
)

mongo_cc_library(
    name = "search_index_commands",
    srcs = [
        "search_index_commands.cpp",
        "search_test_cmds.cpp",
        ":search_index_commands_gen",
    ],
    deps = [
        "//src/mongo/db:commands",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/auth:auth_checks",
        "//src/mongo/db/pipeline",
        "//src/mongo/db/query/search:search_index_common",
        "//src/mongo/db/query/search:search_index_options",
        "//src/mongo/db/query/search:search_index_process_interface",
        "//src/mongo/db/query/search:search_task_executors",
    ],
)

mongo_cc_library(
    name = "query_settings_cmds",
    srcs = [
        # This document source has been re-located here from 'pipeline' to avoid
        # the 'pipeline' -> 'query_settings_service' -> 'pipeline' cyclic
        # dependency. Generating the Debug Query Shape requires re-parsing the
        # query instance via `query_settings::createRepresentativeInfo()`
        # which internally uses `Pipeline::parse()`.
        "//src/mongo/db/exec/agg:query_settings_stage.cpp",
        "//src/mongo/db/pipeline:document_source_query_settings.cpp",
        ":query_settings_cmds_gen",
        "query_settings_cmds.cpp",
    ],
    deps = [
        "//src/mongo/client:clientdriver_minimal",
        "//src/mongo/db:commands",
        "//src/mongo/db:dbdirectclient",
        "//src/mongo/db/commands:set_cluster_parameter_impl",
        "//src/mongo/db/query/plan_cache:query_plan_cache",
        "//src/mongo/db/query/query_settings:query_settings_service",
        "//src/mongo/db/query/query_shape",
        "//src/mongo/db/repl:repl_settings",
        "//src/mongo/db/shard_role/shard_catalog:catalog_helpers",
        "//src/mongo/db/topology/cluster_parameters:cluster_server_parameter_cmds_idl",
        "//src/mongo/s:grid",
    ],
)

mongo_cc_library(
    name = "bulk_write_command",
    srcs = [
        "bulk_write.cpp",
    ],
    deps = [
        ":bulk_write_common",
        ":bulk_write_parser",
        ":update_metrics",
        ":write_commands_common",
        "//src/mongo/crypto:fle_fields",
        "//src/mongo/db:commands",
        "//src/mongo/db:curop_metrics",
        "//src/mongo/db:fle_crud_mongod",
        "//src/mongo/db:local_executor",
        "//src/mongo/db:not_primary_error_tracker",
        "//src/mongo/db:profile_collection",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:service_context",
        "//src/mongo/db/auth",
        "//src/mongo/db/auth:authprivilege",
        "//src/mongo/db/pipeline/process_interface:mongod_process_interfaces",
        "//src/mongo/db/query/client_cursor",
        "//src/mongo/db/query/write_ops",
        "//src/mongo/db/query/write_ops:write_ops_exec",
        "//src/mongo/db/query/write_ops:write_ops_parsers",
        "//src/mongo/db/s:analyze_shard_key_util",
        "//src/mongo/db/s:query_analysis_writer",
        "//src/mongo/db/session:logical_session_id_helpers",
        "//src/mongo/db/shard_role/lock_manager:exception_util",
        "//src/mongo/db/shard_role/shard_catalog:document_validation",
        "//src/mongo/db/stats:server_read_concern_write_concern_metrics",
        "//src/mongo/db/stats:top",
        "//src/mongo/db/storage:storage_options",
        "//src/mongo/db/timeseries/write_ops:timeseries_write_ops",
        "//src/mongo/db/transaction",
        "//src/mongo/logv2:logv2_options",
        "//src/mongo/s:grid",
        "//src/mongo/s:query_analysis_sampler",
        "//src/mongo/util:log_and_backoff",
    ],
)

mongo_cc_library(
    name = "map_reduce_agg",
    srcs = [
        "map_reduce_agg.cpp",
    ],
    deps = [
        ":map_reduce_parser",
        "//src/mongo/db:query_exec",
        "//src/mongo/db:server_base",
        "//src/mongo/db/commands:servers",
        "//src/mongo/db/index:index_access_method",
        "//src/mongo/db/pipeline/process_interface:mongo_process_interface",
        "//src/mongo/db/pipeline/process_interface:mongod_process_interface_factory",
        "//src/mongo/db/query:explain_diagnostic_printer",
        "//src/mongo/db/query:map_reduce_output_format",
        "//src/mongo/db/shard_role",
        "//src/mongo/db/storage:storage_options",
    ],
)

mongo_cc_unit_test(
    name = "map_reduce_agg_test",
    srcs = [
        "map_reduce_agg_test.cpp",
        "map_reduce_parse_test.cpp",
    ],
    tags = ["mongo_unittest_second_group"],
    deps = [
        ":map_reduce_agg",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/auth:authmocks",
        "//src/mongo/db/index_builds:two_phase_index_build_knobs_idl",
        "//src/mongo/db/pipeline:expression_context_for_test",
        "//src/mongo/db/query:query_test_service_context",
    ],
)

mongo_cc_library(
    name = "release_memory_cmd",
    srcs = [
        "release_memory_cmd.cpp",
    ],
    deps = [
        "//src/mongo/db:commands",
        "//src/mongo/db/auth:auth_checks",
        "//src/mongo/db/query:plan_yield_policy_release_memory",
        "//src/mongo/db/query/client_cursor",
    ],
)
